package com.lcq.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class ValidShowStatusValidator implements ConstraintValidator<ValidShowStatus, Integer> {
    private Set<Integer> validValue = new HashSet();
    @Override
    public void initialize(ValidShowStatus constraintAnnotation) {
        if(constraintAnnotation.value()==null){
            return;
        }
        Arrays.stream(constraintAnnotation.value()).forEach((a)->{
            validValue.add(a);
        });
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        return validValue.contains(value);
    }
}
